package com.hotelmanage.hm.serviceImpl;

import com.hotelmanage.hm.mapper.HotelMapper;
import com.hotelmanage.hm.po.HotelPO;
import com.hotelmanage.hm.po.HotelPOExample;
import com.hotelmanage.hm.service.HotelService;
import com.hotelmanage.hm.vo.HotelVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HotelServiceImpl implements HotelService {

    @Resource
    private HotelMapper hotelMapper;

    @Override
    public List<HotelPO> getHotel() {
        HotelPOExample he = new HotelPOExample();
        return hotelMapper.selectByExample(he);
    }

    @Override
    public HotelPO getById(int id) {
        return hotelMapper.selectByPrimaryKey(id);
    }

    @Override
    public int newHotel(HotelVO hotelVO) {
        HotelPO hotelPO = new HotelPO();
        hotelPO.setName(hotelVO.getName());
        hotelPO.setAddress(hotelVO.getAddress());
        hotelPO.setPhone(hotelVO.getPhone());
        hotelPO.setInstruction(hotelVO.getInstruction());
        hotelPO.setStar(hotelVO.getStar());


        return hotelMapper.insertSelective(hotelPO);
    }

    @Override
    public int editHotel(HotelVO hotelVO) {
        HotelPO hotelPO = new HotelPO();
        hotelPO.setId(hotelVO.getId());
        hotelPO.setName(hotelVO.getName());
        hotelPO.setAddress(hotelVO.getAddress());
        hotelPO.setPhone(hotelVO.getPhone());
        hotelPO.setInstruction(hotelVO.getInstruction());
        hotelPO.setStar(hotelVO.getStar());
        return hotelMapper.updateByPrimaryKeySelective(hotelPO);
    }

    @Override
    public int deleteHotel(int hotelid) {
        return hotelMapper.deleteByPrimaryKey(hotelid);
    }
}
